package com.ningkang.common.handler;

import com.ningkang.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName：GlobalExceptionHandler
 * @Author: LeiHao
 * @Date: 2024/10/17 21:36
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@RestControllerAdvice
@Log4j2
public class GlobalExceptionHandler {
    /**
     * 运行异常
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public Result<String> handleRuntimeException(RuntimeException e) {
        return Result.error(e.getMessage());
    }
    /**
     * 最大异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result<String> exception(Exception e) {
        return Result.error(e.getMessage());
    }
}
